<?
$css = file_get_contents("styles/jquery.mobile.custom.theme.css");

$css = str_replace("{", "{\n", $css); //\t
$css = str_replace(";", ";\n", $css); //\t
$css = str_replace("}", "\n}\n\n", $css);

$lines = explode("\n", $css);

foreach ($lines as &$line)
{
	$line = preg_replace('/right(:|;)/', 'temp$1', $line);
	$line = preg_replace('/left(:|;)/', 'right$1', $line);
	$line = preg_replace('/temp(:|;)/', 'left$1', $line);

	$line = preg_replace('/padding:(\d+)px (\d+)px (\d+)px (\d+)px/', 'padding:$1px $4px $3px $2px', $line);
}

$css = implode("\n", $lines); //\r\n

$css = str_replace("{\n", "{", $css); //\t
$css = str_replace(";\n", ";", $css); //\t
$css = str_replace("\n}\n\n", "}", $css);

$extra = "body{direction:rtl}
.ui-icon-arrow-r{background-position: -144px 50%;}
";

file_put_contents("styles/jquery.mobile.custom.theme.rtl.css", $extra.$css);
?>